package com.revivius.jbtorrent;

import com.revivius.jbtorrent.parse.TorrentParser;
import com.revivius.jbtorrent.entity.Torrent;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.ardverk.coding.BencodingInputStream;

/**
 *
 * @author Revivius
 */
public class ParserTest {

    
    
    public static void main(String[] args) {
        try {
            System.out.println(getTorrent());
        } catch (Exception ex) {
            Logger.getLogger(ParserTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static Torrent getTorrent() throws Exception {
        try (InputStream is = ParserTest.class.getResourceAsStream("ac4.torrent");
                BencodingInputStream bis = new BencodingInputStream(is);) {

            
            Map<String, Object> map = bis.readMap(Object.class);
            Torrent torrent = TorrentParser.parse(map);
            
            return torrent;

        } catch (IOException ex) {
            throw ex;
        }
    }
    
}
